package com.rabbitmq.rabbitmqspring.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.rabbitmqspring.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 工作队列监听消息
 */
@Component
@Slf4j
public class WorkListener {

    @RabbitListener(queues = Constants.WORK_QUEUE)
    public void workListener1(Message message, Channel channel) {

        log.info("listener1工作队列模式接收消息, message: {}, channel: {}", message, channel);
    }

    /**
     * message 有两种类型，为 Message 和 String
     * Message 获取到的是消息的完整内容，包括一些参数
     * String 获取到的是消息体
     * @param message
     */
    @RabbitListener(queues = Constants.WORK_QUEUE)
    public void workListener2(String message) {

        log.info("listener2工作队列模式接收消息: {}", message);
    }

}
